home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / monkeysphere-authentication < prev    next >
Encoding:
Text File  |  2011-03-24  |  6.3 KB  |  231 lines

  1. #!/usr/bin/env bash
  2.  
  3. # monkeysphere-authentication: Monkeysphere authentication admin tool
  4. #
  5. # The monkeysphere scripts are written by:
  6. # Jameson Rollins <jrollins@finestructure.net>
  7. # Jamie McClelland <jm@mayfirst.org>
  8. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  9. # Micah Anderson <micah@riseup.net>
  10. #
  11. # They are Copyright 2008-2009, and are all released under the GPL,
  12. # version 3 or later.
  13.  
  14. ########################################################################
  15. set -e
  16.  
  17. # set the pipefail option so pipelines fail on first command failure
  18. set -o pipefail
  19.  
  20. PGRM=$(basename $0)
  21.  
  22. SYSSHAREDIR=${MONKEYSPHERE_SYSSHAREDIR:-"/usr/share/monkeysphere"}
  23. export SYSSHAREDIR
  24. . "${SYSSHAREDIR}/defaultenv"
  25. . "${SYSSHAREDIR}/common"
  26.  
  27. # sharedir for authentication functions
  28. MASHAREDIR="${SYSSHAREDIR}/ma"
  29.  
  30. # datadir for authentication functions
  31. MADATADIR="${SYSDATADIR}/authentication"
  32.  
  33. # temp directory to enable atomic moves of authorized_keys files
  34. MATMPDIR="${MADATADIR}/tmp"
  35. export MATMPDIR
  36.  
  37. # UTC date in ISO 8601 format if needed
  38. DATE=$(date -u '+%FT%T')
  39.  
  40. # unset some environment variables that could screw things up
  41. unset GREP_OPTIONS
  42.  
  43. ########################################################################
  44. # FUNCTIONS
  45. ########################################################################
  46.  
  47. usage() {
  48.     cat <<EOF >&2
  49. usage: $PGRM <subcommand> [options] [args]
  50. Monkeysphere authentication admin tool.
  51.  
  52. subcommands:
  53.  update-users (u) [USER]...        update user authorized_keys files
  54.  keys-for-user (k) USER            output user authorized_keys lines to stdout
  55.  refresh-keys (r)                  refresh keys in keyring
  56.  
  57.  add-id-certifier (c+) KEYID|FILE  import and tsign a certification key
  58.    [--domain (-n) DOMAIN]            limit ID certifications to DOMAIN
  59.    [--trust (-t) TRUST]              trust level of certifier (default: full)
  60.    [--depth (-d) DEPTH]              trust depth for certifier (default: 1)
  61.  remove-id-certifier (c-) KEYID    remove a certification key
  62.  list-id-certifiers (c)            list certification keys
  63.  
  64.  version (v)                       show version number
  65.  help (h,?)                        this help
  66.  
  67. See ${PGRM}(8) for more info.
  68. EOF
  69. }
  70.  
  71. # function to interact with the gpg core keyring
  72. gpg_core() {
  73.     GNUPGHOME="$GNUPGHOME_CORE"
  74.     export GNUPGHOME
  75.  
  76.     gpg --fixed-list-mode --no-greeting --quiet --no-tty "$@"
  77. }
  78.  
  79. # function to interact with the gpg sphere keyring
  80. gpg_sphere() {
  81.     GNUPGHOME="$GNUPGHOME_SPHERE"
  82.     export GNUPGHOME
  83.  
  84.     su_monkeysphere_user "gpg --fixed-list-mode --no-greeting --quiet --no-tty $@"
  85. }
  86.  
  87. # output to stdout the core fingerprint from the gpg core secret
  88. # keyring
  89. core_fingerprint() {
  90.     log debug "determining core key fingerprint..."
  91.     gpg_core --list-secret-key --with-colons \
  92.         --with-fingerprint \
  93.     | grep ^fpr: | cut -d: -f10
  94. }
  95.  
  96. # export signatures from core to sphere
  97. gpg_core_sphere_sig_transfer() {
  98.     log debug "exporting core local sigs to sphere..."
  99.     gpg_core --export-options export-local-sigs --export | \
  100.     gpg_sphere --import-options import-local-sigs --import 2>&1 | log debug
  101. }
  102.  
  103. ########################################################################
  104. # MAIN
  105. ########################################################################
  106.  
  107. # set unset default variables
  108. AUTHORIZED_USER_IDS="%h/.monkeysphere/authorized_user_ids"
  109. RAW_AUTHORIZED_KEYS="%h/.ssh/authorized_keys"
  110.  
  111. # load configuration file
  112. [ -e ${MONKEYSPHERE_AUTHENTICATION_CONFIG:="${SYSCONFIGDIR}/monkeysphere-authentication.conf"} ] \
  113.     && . "$MONKEYSPHERE_AUTHENTICATION_CONFIG"
  114.  
  115. # set empty config variable with ones from the environment
  116. LOG_LEVEL=${MONKEYSPHERE_LOG_LEVEL:=$LOG_LEVEL}
  117. KEYSERVER=${MONKEYSPHERE_KEYSERVER:=$KEYSERVER}
  118. CHECK_KEYSERVER=${MONKEYSPHERE_CHECK_KEYSERVER:=$CHECK_KEYSERVER}
  119. MONKEYSPHERE_USER=${MONKEYSPHERE_MONKEYSPHERE_USER:=$MONKEYSPHERE_USER}
  120. MONKEYSPHERE_GROUP=$(get_primary_group "$MONKEYSPHERE_USER")
  121. PROMPT=${MONKEYSPHERE_PROMPT:=$PROMPT}
  122. AUTHORIZED_USER_IDS=${MONKEYSPHERE_AUTHORIZED_USER_IDS:=$AUTHORIZED_USER_IDS}
  123. RAW_AUTHORIZED_KEYS=${MONKEYSPHERE_RAW_AUTHORIZED_KEYS:=$RAW_AUTHORIZED_KEYS}
  124. STRICT_MODES=${MONKEYSPHERE_STRICT_MODES:=$STRICT_MODES}
  125.  
  126. # other variables
  127. REQUIRED_USER_KEY_CAPABILITY=${MONKEYSPHERE_REQUIRED_USER_KEY_CAPABILITY:="a"}
  128. GNUPGHOME_CORE=${MONKEYSPHERE_GNUPGHOME_CORE:="${MADATADIR}/core"}
  129. GNUPGHOME_SPHERE=${MONKEYSPHERE_GNUPGHOME_SPHERE:="${MADATADIR}/sphere"}
  130. CORE_KEYLENGTH=${MONKEYSPHERE_CORE_KEYLENGTH:="2048"}
  131. LOG_PREFIX=${MONKEYSPHERE_LOG_PREFIX:='ms: '}
  132.  
  133. # export variables needed in su invocation
  134. export DATE
  135. export LOG_LEVEL
  136. export KEYSERVER
  137. export MONKEYSPHERE_USER
  138. export MONKEYSPHERE_GROUP
  139. export PROMPT
  140. export CHECK_KEYSERVER
  141. export REQUIRED_USER_KEY_CAPABILITY
  142. export GNUPGHOME_CORE
  143. export GNUPGHOME_SPHERE
  144. export GNUPGHOME
  145. export CORE_KEYLENGTH
  146. export LOG_PREFIX
  147.  
  148. if [ "$#" -eq 0 ] ; then 
  149.     usage
  150.     failure "Please supply a subcommand."
  151. fi
  152.  
  153. # get subcommand
  154. COMMAND="$1"
  155. shift
  156.  
  157. case $COMMAND in
  158.     'setup'|'setup'|'s')
  159.     source "${MASHAREDIR}/setup"
  160.     setup
  161.     ;;
  162.  
  163.     'update-users'|'update-user'|'update'|'u')
  164.     source "${MASHAREDIR}/setup"
  165.     setup
  166.     source "${MASHAREDIR}/update_users"
  167.     OUTPUT_STDOUT= update_users "$@"
  168.     ;;
  169.  
  170.     'keys-for-user'|'k')
  171.     (( $# > 0 )) || failure "Must specify user."
  172.     source "${MASHAREDIR}/setup"
  173.     setup
  174.     source "${MASHAREDIR}/update_users"
  175.     OUTPUT_STDOUT=true update_users "$1"
  176.     ;;
  177.  
  178.     'refresh-keys'|'refresh'|'r')
  179.     source "${MASHAREDIR}/setup"
  180.     setup
  181.     gpg_sphere --keyserver "$KEYSERVER" --refresh-keys
  182.     ;;
  183.  
  184.     'add-identity-certifier'|'add-id-certifier'|'add-certifier'|'c+')
  185.     source "${MASHAREDIR}/setup"
  186.     setup
  187.     source "${MASHAREDIR}/add_certifier"
  188.     add_certifier "$@"
  189.     ;;
  190.  
  191.     'remove-identity-certifier'|'remove-id-certifier'|'remove-certifier'|'c-')
  192.     source "${MASHAREDIR}/setup"
  193.     setup
  194.     source "${MASHAREDIR}/remove_certifier"
  195.     remove_certifier "$@"
  196.     ;;
  197.  
  198.     'list-identity-certifiers'|'list-id-certifiers'|'list-certifiers'|'list-certifier'|'c')
  199.     source "${MASHAREDIR}/setup"
  200.     setup
  201.     source "${MASHAREDIR}/list_certifiers"
  202.     list_certifiers
  203.     ;;
  204.  
  205.     'diagnostics'|'d')
  206.     source "${MASHAREDIR}/setup"
  207.     setup
  208.     source "${MASHAREDIR}/diagnostics"
  209.     diagnostics
  210.     ;;
  211.  
  212.     'gpg-cmd')
  213.     source "${MASHAREDIR}/setup"
  214.     setup
  215.     gpg_sphere "$@"
  216.     ;;
  217.  
  218.     'version'|'--version'|'v')
  219.     version
  220.     ;;
  221.  
  222.     '--help'|'help'|'-h'|'h'|'?')
  223.         usage
  224.         ;;
  225.  
  226.     *)
  227.         failure "Unknown command: '$COMMAND'
  228. Try '$PGRM help' for usage."
  229.         ;;
  230. esac
  231.